<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title>我的收货地址</title>
  <link type="text/css" rel="stylesheet" th:href="@{/css/page.css}" />
  <script type="text/javascript" th:src="@{/js/jquery-3.3.1.js}" ></script>
  <!-- validation -->
  <script type="text/javascript" th:src="@{/js/jquery.validate.js}" ></script>
  <!-- layer -->
  <link type="text/css" rel="stylesheet" th:href="@{/css/layui.css}" />
  <script type="text/javascript" th:src="@{/js/layui.js}"  charset="utf-8"></script>


  <link type="text/css" rel="stylesheet" th:href="@{/css/layer.css}"/>
  <script type="text/javascript" th:src="@{/js/layer.js}" ></script>


  <style type="text/css">


    .need_span{
      color: red;
      display: none;
    }
    .need_0, .validation_span{
      color: red;
    }
    .need_1{
      color: #666666;
    }
    .input_0{
      width: 200px;
    }
    .form_table td{
      padding: 5px;
    }
    .text_ad_0{
      font-weight: bold;
      color: #444444;
      white-space: nowrap;
    }
  </style>


  <script type="text/javascript"  th:inline="javascript">


    layui.use('laydate', function(){
      var laydate = layui.laydate;

      //执行一个laydate实例
      laydate.render({
        elem: '#userBirthday' //指定元素
      });
    });


    function getTime(val){
      if(val){
        val = val.split("T");
        return val[0];
      }
      return "";
    }

    var manageFoot = [[${manageFoot}]];


    $(function(){
      $(".re_password").hide();
      if(manageFoot){
        //修改
        $(".top_page_name").text("修改菜单");

        //回填值
        console.log(manageFoot);
        $("#breakfast").val(manageFoot.breakfast);
        $("#lunch").val(manageFoot.lunch);
        $("#dinner").val(manageFoot.dinner);
        //$(":radio[name='userSex'][value='"+manageUser.userSex+"']").attr("checked", "checked");
      }

      //开始验证
      $('form').validate({

        submitHandler: function (){
          save();
        }
      });

      //返回按钮
      $("#backBtu").click(function(){
        layer.confirm('确认返回吗？', {icon: 3, title:'提示'}, function(index){
          parent.layer.closeAll();
        });
      });
    });


    function closeSelf(){
      var i = layer.getFrameIndex();
      layer.close(i);
    }


    //保存
    function save(){
      var param = new Object();
      param.address_name = $.trim($("#address_name").val());
      param.uphone = $.trim($("#uphone").val());
      param.email = $.trim($("#email").val());
      param.address_detail = $.trim($("#address_detail").val());
      param.address_in_detail = $.trim($("#address_in_detail").val());
      param.address_remark = $.trim($("#address_remark").val());
      var urlStr = "/address/toAddressAdd";

      if(manageFoot){
        //修改
        param.id = manageFoot.id
        urlStr = "/admin/updateFoot";

      }

      if(param.address_name=="" || param.uphone==""|| param.email==""|| param.address_detail==""|| param.address_in_detail==""|| param.address_remark==""){
        layer.confirm('请填写必填项!', {icon: 2, title:'提示'});
      }else{

        layer.confirm('确认保存吗？', {icon: 3, title:'提示'}, function(index){
          $.ajax({
            type:"POST",
            async:true,  //默认true,异步
            data:param,
            url:urlStr,
            success:function(data){
              console.log(data);
              if(data == "SUCCESS"){
                layer.alert('保存成功！', {icon: 1}, function(indexOk){
                  parent.search();
                  parent.$("#add_iframe iframe").attr("src", "");
                  parent.$("div").first().show();
                  parent.$("#add_iframe").hide();
                  parent.layer.closeAll();
                });
              }else if(data == "LGINOUT"){
                //重新登录
                parent.window.location.href = "/logout";
              }else{
                layer.alert('保存失败！', {icon: 2}, function(indexNo){
                  parent.layer.closeAll();
                });
              }
            }
          });
        });
      }
    }


  </script>
</head>
<body>
<div  style="margin-left:15px; height: 400px;">
  <div class="first_div" style="border:none;">
    <div id="adListDiv" align="left" >
      <form>
        <table class="form_table" style="border-collapse: collapse;margin-left:20px;margin-top:10px;">

          <tr>
            <td align="right" >
              <span class="need_0">*</span>
              <span class="text_ad_0">收货人姓名：</span>
            </td>
            <td>
              <input id="address_name" type="text" name="address_name" class="input_0" />
              <span class="validation_span"></span>
            </td>
          </tr>

          <tr>
            <td align="right" >
              <span class="need_0">*</span>
              <span class="text_ad_0">手机号码：</span>
            </td>
            <td>
              <input id="uphone" type="text" name="uphone" class="input_0" />
              <span class="validation_span"></span>
            </td>
          </tr>

          <tr>
            <td align="right" >
              <span class="need_0">*</span>
              <span class="text_ad_0">电子邮件：</span>
            </td>
            <td>
              <input id="email" type="text" name="email" class="input_0" />
              <span class="validation_span"></span>
            </td>
          </tr>

          <tr>
            <td align="right" >
              <span class="need_0">*</span>
              <span class="text_ad_0">所在地区：</span>
            </td>
            <td>
              <input id="address_detail" type="text" name="address_detail" class="input_0" />
              <span class="validation_span"></span>
            </td>
          </tr>

          <tr>
            <td align="right" >
              <span class="need_0">*</span>
              <span class="text_ad_0">详细地址：</span>
            </td>
            <td>
              <textarea id="address_in_detail" name="address_in_detail" style="width: 200px;" rows="3"></textarea>
              <span class="validation_span"></span>
            </td>
          </tr>

          <tr>
            <td align="right" >
              <span class="need_0">*</span>
              <span class="text_ad_0">备注：</span>
            </td>
            <td>
              <textarea id="address_remark" name="address_remark" style="width: 200px;" rows="3"></textarea>
              <span class="validation_span"></span>
            </td>
          </tr>

          <tr>
            <td colspan="2" align="left" >
              <div style="margin-top:10px;margin-bottom:20px;margin-left:120px;">
                <input type="submit" class="layui-btn" lay-submit="" lay-filter="add" id="saveBtu" name="saveBtu" value="保存" style="" />
                <input type="button" class="layui-btn" lay-submit="" lay-filter="add" id="backBtu" name="backBtu" value="返回" style="margin-left:20px;" />
              </div>
            </td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
</body>
</html>